package com.dream.model.app;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.dream.model.base.AppUserModelBase;

@Entity
@Table(name="t_app_user_resource")
public class AppUserResource extends AppUserModelBase implements Serializable {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8084812212817853933L;

	@EmbeddedId
	private AppUserResourcePK id;
	
	@Column(name="deleted")
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private boolean deleted;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="resource_id",updatable=false,insertable=false)
	private AppResource appResource;
	
	public AppResource getAppResource() {
		return appResource;
	}

	public void setAppResource(AppResource appResource) {
		this.appResource = appResource;
	}

	public AppUserResourcePK getId() {
		return id;
	}

	public void setId(AppUserResourcePK id) {
		this.id = id;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AppUserResource other = (AppUserResource) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	@Embeddable 
	public static class  AppUserResourcePK implements Serializable{
		
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Column(name="user_id")
		private String userId ;
		
		@Column(name="resource_id")
		private long resourceId;

		public String getUserId() {
			return userId;
		}

		public void setUserId(String userId) {
			this.userId = userId;
		}

		public long getResourceId() {
			return resourceId;
		}

		public void setResourceId(long resourceId) {
			this.resourceId = resourceId;
		}
		
		
	}
	
}
